#include "asio_Network.h"

namespace XGC
{
	namespace net
	{
		asio_NetworkBase::asio_NetworkBase(void)
		{
		}

		asio_NetworkBase::~asio_NetworkBase(void)
		{
			shutdown();
		}

		xgc_void asio_NetworkBase::handle_quit()
		{
			return;
		}

		xgc_void asio_NetworkBase::run()
		{
			io_service::work w( _service );
			_service.run();
		}

		xgc_bool asio_NetworkBase::insert_workthread( xgc_int32 insert_workthread )
		{
			for( int i = 0; i < insert_workthread; ++i )
			{
				_workthreads.push_back( shared_ptr<thread>( new thread( bind( &asio_NetworkBase::run, this ) ) ) );
			}

			return true;
		}

		xgc_void asio_NetworkBase::shutdown()
		{
			_service.stop();

			for( size_t i = 0; i < _workthreads.size(); ++ i )
			{
				_workthreads[i]->join();
			}
		}
	}
}
